<template>
	<view>
		<view class="container">
			<view class="center_slot">
				<view class="flex-box areas plr30">
					<navigator url="/pages/home/locate/locate" hover-class="none">
						<view class="city-picker flex-box flex-center">{{ now_city }}</view>
					</navigator>
					<!-- #ifndef MP -->
					<navigator url="/pages/home/search/search" class="flex-box  flex-grow-1 mr30 inputbox">
						<image src="/static/icon/h-icon_sou.png" class="icon_search"></image>
						<input disabled :value="searchCheckJson.keyword" class="fs22 flex-grow-1"
							placeholder="请输入你要查找的内容"></input>
						<image src="/static/icon/close.png" class="icon_direct" v-if="searchCheckJson.keyword"
							style="width:40rpx;height:40rpx;" @tap.stop.prevent="delKeywords"></image>
					</navigator>
					<!-- #endif -->
					<!-- #ifdef MP -->
					<navigator url="/pages/home/search/search" class="flex-box flex-grow-1 mr30 inputbox"
						style="width: 350rpx;">
						<image src="/static/icon/h-icon_sou.png" class="icon_search"></image>
						<input disabled :value="searchCheckJson.keyword" class="fs22 flex-grow-1"
							placeholder="请输入你要查找的内容"></input>
						<image src="/static/icon/close.png" class="icon_direct" v-if="searchCheckJson.keyword"
							style="width:40rpx;height:40rpx;" @tap.stop.prevent="delKeywords"></image>
					</navigator>
					<!-- #endif -->
					<!-- #ifndef H5 -->
					<navigator url="/pages/home/map_search/map_search" hover-class="none" class="tc">
						<image src="/static/icon/h-icon_map.png" class="icon_map" mode=""></image>
						<view class="fs26 col10">地图找房</view>
					</navigator>
					<!-- #endif -->
				</view>
				<view class="flex-box sortbox">
					<!-- <view
						:class="'sortitem ' + (regionStatus || searchCheckJson.nearby || searchCheckJson.region || searchCheckJson.subway_id ? 'active' : '')"
						@tap="openarea">
						区域
					</view> -->
					<view class="sortitem" :class="{squareStatus:'active'}" @tap="opensquare">
						面积
					</view>
					<view
						:class="'sortitem ' + (priceStatus || searchCheckJson.max_average_price || searchCheckJson.max_total_price ? 'active' : '')"
						@tap="openprice">价格</view>
					<view
						:class="'sortitem ' + (houseStatus || searchCheckJson.search_roomnum_ids != '' ? 'active' : '')"
						@tap="openhouse">户型</view>
					<view
						:class="'sortitem ' + (moreStatus || searchCheckJson.sale_state || searchCheckJson.type_ids || searchCheckJson.developer_ids ? 'active' : '')"
						@tap="openmore">
						更多
					</view>
				</view>
			</view>
			<view class="houselist">
				<template v-if="houseList.total > 0">

					<view class="houseitem flex" v-for="(item, index) in houseList.data" @click="goToDe(item)">
						<view class="houseimg">
							<u--image :showLoading="true" :lazy-load="true" :src="item.image_text" radius="10rpx" width="240rpx" height="190rpx" mode="aspectFill"></u--image>
						</view>
						<view class="flex-grow-1">
							<view class="flex-box">
								<view class="housename m-ellipsis flex-grow-1 fwb">{{item.name}}</view>
								<view class="sale_type1">{{ item.sale_state_text }}</view>
							</view>
							<view class="area-size">
								
								<text class="pr20">{{ item.list_labels?item.list_labels:'' }}</text>
								<text v-if="false">| {{ item.alias_name ? item.alias_name : '' }}</text>
								
								<text>建面{{ item.min_space }}㎡</text>
							</view>
							<view class="targetbox flex">
								<view class="targetitem" v-for="(targets, index1) in item.house_tag_ids_text_arr">
									{{targets}}
								</view>
								<view v-if="item.rank_json_text" class="number_one">
									<image src="/static/icon/icon_reward.png" class="icon_reward"></image>
									<view>{{ item.rank_json_text }}</view>
								</view>
							</view>
							<view class="housecost fwb">
								<!-- 新房 -->
								<text class="pr20" v-if="item.house_type_id==16">{{ item.price }}万</text>
								<!-- 二手房 -->
								<text class="pr20" v-if="item.house_type_id==1">{{ item.price }}万</text>
								{{ item.first_price_msg ? item.first_price_msg : '' }}
								<text class="junjia" v-if="item.house_type_id==1">{{item.unit_price}}元/平</text>
								<!-- 商铺 -->
								<text class="pr20" v-if="item.house_type_id==18">{{ item.price }}万</text>
								<text class="junjia" v-if="item.house_type_id!=1">{{item.unit_price}}元/平(参考均价)</text>
							</view>
							
							<view class="area-size" v-if="item.house_type_id==16">
								<text class="pr20">楼盘地址</text>
								<text style="color:#000;"> {{ item.region + item.addr}}</text>
							</view>
						</view>
					</view>

					<u-loadmore :status="loadStatus" fontSize="24" line loading-text="努力加载中" loadmore-text="轻轻上拉"
						nomore-text="没有更多了" />
				</template>
				<template v-else>
					<u-empty mode="data" text="暂无数据" textSize="24" icon="/static/images/none-data.png">
					</u-empty>
				</template>
			</view>
		</view>

		<!-- <button @tap="addAppointLog" data-type="2" data-subtype="0" class="consult_btn flex-box flex-col flex-center">
			<image src="/static/icon/icon_kefu-b.png"></image>
			<view class="fs20 col3 pt10">咨询</view>
		</button> -->
		<view @tap="bindPhoneCall" data-type="2" class="consult_btn flex-box flex-col flex-center">
			<image src="/static/icon/icon_kefu-b.png"></image>
			<view class="fs20 col3 pt10">咨询</view>
		</view>

		<!-- 预约弹窗start -->
		<u-popup :show="popupStatus" mode="center" round="8" @close="closePopupStatus" closeOnClickOverlay>
			<view class="zixun-pop">
				<view class="fs40 black tc mb20">我要咨询</view>
				<view class="fs30 col-darkGray tc mb40">
					<view>虹桥金茂悦有哪些劣势？性价比如何？</view>
					<view>还有什么类似楼盘推荐……</view>
					<view>更多问题，咨询师帮你答疑解惑</view>
				</view>
				<view class="input-box flex-box plr30 mb40" v-if="popupStatus"><input @input="appoint_mobileFun"
						:value="appoint_mobile" class="input flex-grow-1" type="number" placeholder="请输入手机号码"
						placeholder-style="color:#ccc;" /></view>
				<view @tap="submitAppointLog" class="btn1 mb30">确认</view>
				<!-- <view @tap="jumpToChat" :data-uid="broker_user_id" class="btn2 mb20">立即微聊</view> -->
				<button open-type="contact" class="btn2 mb20">立即微聊</button>
			</view>
		</u-popup>
		<!-- 预约弹窗end -->
		<!-- 预约成功弹窗start -->
		<u-popup :show="reserveStatus" mode="center" closeable :safeAreaInsetBottom="false" @close="closeReserveStatus">
			<view class="reserve">
				<image src="/static/icon/icon_reserve.png" class="icon_reserve"></image>
				<view class="title1">预约成功</view>
				<view class="title2">用手机号码{{ appoint_mobile_text }}预约了咨询服务，稍后经纪人将为您解答疑问，请注意接听电话</view>
				<button @tap="closeReserveStatus" class="reserve-btn1">好的</button>
				<!-- <button @tap="jumpToChat" :data-uid="broker_user_id" class="reserve-btn2">立即微聊</button> -->
				<button open-type="contact" class="reserve-btn2">立即微聊</button>
			</view>
		</u-popup>
		<!-- 预约成功弹窗end -->
		<u-popup :show="regionStatus" mode="top" @close="closePopup" :safeAreaInsetBottom="false">
			<view class="pricewrap" style="padding-top: 178rpx;">
				<view class="flex-box">
					<view class="singleprice">
						<view @tap="choosesearchtype" data-type="1"
							:class="'price-left ' + (search_type == 1 ? 'active' : '')">区域</view>
						<view v-if="subwayData.length > 0" @tap="choosesearchtype" data-type="2"
							:class="'price-left ' + (search_type == 2 ? 'active' : '')">地铁</view>
						<view @tap="choosesearchtype" data-type="3"
							:class="'price-left ' + (search_type == 3 ? 'active' : '')">附近</view>
					</view>
					<template v-if="search_type == 1">
						<scroll-view scroll-y="true" :class="'rangeprice '+(now_area_index > 0?'leftline':'')">
							<view :class="'price-right ' + (now_area_index == 0 ? 'active' : '')" @tap="chooseregion"
								data-index="0">不限</view>
							<template v-for="(item, index) in areaData">
								<view
									:class="'price-right single-line ' + (now_area_index - 1 == index ? 'active' : '')"
									@tap="chooseregion" :data-index="index + 1">
									{{ item.name }}
								</view>
							</template>
						</scroll-view>
						<scroll-view scroll-y="true" v-if="now_area_index > 0" class="rangeprice rightline">
							<view :class="'price-right ' + (searchCheckJson.street == '' ? 'active' : '')"
								@tap="choosestreet" data-index="0">不限</view>
							<template v-for="(item, index) in nowStreetData">
								<view
									:class="'price-right single-line ' + (searchCheckJson.street == item.name ? 'active' : '')"
									@tap="choosestreet" :data-index="index + 1">
									{{ item.name }}
								</view>
							</template>
						</scroll-view>
					</template>
					<template v-else-if="search_type == 2">
						<scroll-view scroll-y="true" :class="'rangeprice '+(now_subway_index > 0?'leftline':'')">
							<view :class="'price-right ' + (now_subway_index == 0 ? 'active' : '')" @tap="choosesubway"
								data-index="0">不限</view>
							<template v-for="(item, index) in subwayData">
								<view
									:class="'price-right single-line ' + (now_subway_index - 1 == index ? 'active' : '')"
									@tap="choosesubway" :data-index="index + 1">{{ item.name }}</view>
							</template>
						</scroll-view>
						<scroll-view scroll-y="true" v-if="now_subway_index > 0" class="rangeprice rightline">
							<view
								:class="'price-right single-line ' + (searchCheckJson.subway_platform_id ? '' : 'active')"
								@tap="chooseplatform" data-index="0">不限</view>
							<template v-for="(item, index) in nowPlatformData">
								<view
									:class="'price-right single-line ' + (searchCheckJson.subway_platform_id == item.id ? 'active' : '')"
									@tap="chooseplatform" :data-index="index + 1">
									{{ item.name }}
								</view>
							</template>
						</scroll-view>
					</template>
					<template v-else-if="search_type == 3">
						<scroll-view scroll-y="true" class="rangeprice">
							<view :class="'price-right ' + (searchCheckJson.nearby ? '' : 'active')" @tap="choosenearby"
								data-nearby="0">不限</view>
							<view :class="'price-right ' + (searchCheckJson.nearby == 1 ? 'active' : '')"
								@tap="choosenearby" data-nearby="1">1km</view>
							<view :class="'price-right ' + (searchCheckJson.nearby == 2 ? 'active' : '')"
								@tap="choosenearby" data-nearby="2">2km</view>
							<view :class="'price-right ' + (searchCheckJson.nearby == 3 ? 'active' : '')"
								@tap="choosenearby" data-nearby="3">3km</view>
						</scroll-view>
					</template>
				</view>
			</view>
		</u-popup>
		<u-popup :show="priceStatus" mode="top" :safeAreaInsetBottom="false" @close="openprice">
			<view class="pricewrap" style="padding-top: 178rpx;">
				<view class="flex-box">
					<view class="singleprice">
						<view :class="'price-left ' + (is_single ? 'active' : '')" @tap="chooseissingle">单价</view>
						<view :class="'price-left ' + (is_single ? '' : 'active')" @tap="chooseissingle">总价</view>
					</view>
					<scroll-view v-if="is_single" scroll-y="true" class="rangeprice">
						<template v-for="(item, index) in searchData.priceData">
							<view v-if="item.type == 1" :class="'price-right ' + (item.is_choose ? 'active' : '')"
								:data-index="index" @tap="chooseprice">{{ item.name }}</view>
						</template>
					</scroll-view>
					<scroll-view v-else scroll-y="true" class="rangeprice">
						<template v-for="(item, index) in searchData.priceData">
							<view v-if="item.type == 2" :class="'price-right ' + (item.is_choose ? 'active' : '')"
								:data-index="index" @tap="chooseprice">{{ item.name }}</view>
						</template>
					</scroll-view>
				</view>
				<view class="flex-box flex-center inputrange">
					<view v-if="is_single" class="flex-box">
						<input class="fs30" @input="min_average_price_fuc" :value="min_average_price" type="digit"
							v-if="priceStatus" placeholder="最小" />
						<view class="line">-</view>
						<input class="fs30" @input="max_average_price_fuc" :value="max_average_price" type="digit"
							v-if="priceStatus" placeholder="最大" />
						<!-- <view class="wan">万</view> -->
					</view>
					<view v-else class="flex-box">
						<input class="fs30" @input="min_total_price_fuc" :value="min_total_price" type="digit"
							v-if="priceStatus" placeholder="最小" />
						<view class="line">-</view>
						<input class="fs30" @input="max_total_price_fuc" :value="max_total_price" type="digit"
							v-if="priceStatus" placeholder="最大" />
						<view class="wan">万</view>
					</view>
					<button class="sure" @tap="confirmprice">确定</button>
				</view>
			</view>
		</u-popup>

		<u-popup :show="houseStatus" mode="top" :safeAreaInsetBottom="false" @close="openhouse">
			<view class="housewrap" style="padding-top: 178rpx;">
				<scroll-view scroll-y="true" class="checkgroup">
					<view class="flex-box  flex-between checkitem fs30" @tap="chooseroomnum" :data-index="index"
						v-for="(item, index) in searchData.roomnumData">
						<view :class="item.is_choose ? 'col009' : ''">{{ item.name }}</view>
						<image :src="'/static/icon/icon_choose' + (item.is_choose ? '-on' : '') + '.png'"
							class="choose"></image>
					</view>
				</scroll-view>
				<view class="flex-box  flex-between btuttons">
					<button hover-class="none" class="btn1" @tap="clearroomnum">清空</button>
					<button hover-class="none" class="btn2" @tap="confirmroomnum">确定</button>
				</view>
			</view>
		</u-popup>


		<u-popup :show="squareStatus" mode="top" :safeAreaInsetBottom="false" @close="openmore">
			<view class="morewrap" style="padding-top: 178rpx;">
				
				<scroll-view scroll-y="true" class="morebox" style="height:auto;min-height:20vh;">
					<view class="moreitem">
						<view class="moretitle">面积</view>
						<view class="flex-box flex-wrap">
							<view :data-id="item.id" @tap="chooseSquare" class="items" :class="{'active':item.id==sid}" v-for="(item, index) in squareArr">
								{{ item.name }}
							</view>
						</view>
					</view>
					
				</scroll-view>
				<view class="flex-box  flex-between btuttons">
					<button class="btn1" @tap="clearmore">清空</button>
					<button class="btn2" @tap="confirmSquare">确定</button>
				</view>
			</view>
		</u-popup>

		<u-popup :show="moreStatus" mode="top" :safeAreaInsetBottom="false" @close="openmore">
			<view class="morewrap" style="padding-top: 178rpx;">
				<scroll-view scroll-y="true" class="morebox">
					<view class="moreitem">
						<view class="moretitle">类型 <text>（可多选）</text></view>
						<view class="flex-box flex-wrap">
							<view :data-index="index" @tap="choosetype"
								:class="'items ' + (item.is_choose ? 'active' : '')"
								v-for="(item, index) in searchData.typeData">
								{{ item.name }}
							</view>
						</view>
					</view>
					<view class="moreitem">
						<view class="moretitle">
							售卖情况
							<text></text>
						</view>
						<view class="flex-box flex-wrap">
							<view @tap="choosesalestate" data-type="1"
								:class="'items ' + (choose_sale_state == 1 ? 'active' : '')">在售</view>
							<view @tap="choosesalestate" data-type="2"
								:class="'items ' + (choose_sale_state == 2 ? 'active' : '')">售罄</view>
							<view @tap="choosesalestate" data-type="3"
								:class="'items ' + (choose_sale_state == 3 ? 'active' : '')">待售</view>
						</view>
					</view>
					<view class="moreitem" v-if="false">
						<view class="moretitle">
							开发商
							<text>（可多选）</text>
						</view>
						<view class="flex-box flex-wrap">
							<view :data-index="index" @tap="choosedeveloper" v-if="index < moredev"
								:class="'items ' + (item.is_choose ? 'active' : '')"
								v-for="(item, index) in searchData.developerData">
								{{ item.name }}
							</view>
							<view v-if="moredev == 3" @tap="showAllDev" class="items mores">更多+</view>
						</view>
					</view>
				</scroll-view>
				<view class="flex-box  flex-between btuttons">
					<button class="btn1" @tap="clearmore">清空</button>
					<button class="btn2" @tap="confirmmore">确定</button>
				</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	const app = getApp();

	const functions = require('../../../utils/functions.js');
	export default {
		data() {
			return {
				loadStatus: 'loadmore', //加载状态

				popupStatus: false,
				//订阅咨询预约弹窗
				reserveStatus: false,
				//预约成功弹窗
				// 预约订阅类型
				appoint_type: 1,
				//分类:1=订阅动态,2=留电咨询,3=领取免费专车,4=帮你找房,5=咨询房价走势
				// 订阅分类
				appoint_subscribe_type: 0,
				//订阅通知类型:0=无订阅,1=订阅变价通知,2=订阅开盘通知,3=订阅实时动态
				// 预约手机号
				appoint_mobile: '',
				appoint_mobile_text: '',
				broker_user_id: 0,

				// 当前城市
				now_city: '锡林郭勒盟',

				// 城市其下区县、街道
				areaData: [],

				// 城市其下地铁数据
				subwayData: [],
				
				// 面积
				squareArr:[//面积
					{
						id:1,
						name:'50m²以下',
						is_choose:false,
					},
					{
						id:2,
						name:'50-70m²',
						is_choose:false,
					},
					{
						id:3,
						name:'70-90m²',
						is_choose:false,
					},
					{
						id:4,
						name:'90-120m²',
						is_choose:false,
					},
					{
						id:5,
						name:'120-150m²',
						is_choose:false,
					},
					{
						id:6,
						name:'150-200m²',
						is_choose:false,
					},
					{
						id:7,
						name:'200m²以上',
						is_choose:false,
					},
					
				],
				sid:'',

				// 房源搜索条件
				searchData: {
					priceData: [],
					//获取搜索价格
					roomnumData: [],
					//获取搜索户型
					typeData: [],
					//类型
					developerData: [],
					//品牌开发商
					tagData: [] ,//tag标签
				},
				// 房源列表
				houseList: {
					total: 0,
					current_page: 0,
					last_page: 1,
					data: []
				},

				// 已选中的搜索条件
				searchCheckJson: {
					region: '',
					//区域
					street: '',
					//街道/镇
					keyword: '',
					//搜索关键词
					lat: '',
					//纬度
					lng: '',
					//经度
					nearby: '',
					//附近几公里
					subway_id: '',
					//地铁线id
					subway_platform_id: '',
					//地铁站id
					min_average_price: '',
					//最小单价（万元）
					max_average_price: '',
					//最大单价（万元）（-1为无限大）
					min_total_price: '',
					//最小总价（万元）
					max_total_price: '',
					//最大总价（万元）（-1为无限大）
					search_roomnum_ids: '',
					//查询户型(多个id用英文逗号隔开)
					type_ids: '',
					//查询类型(多个id用英文逗号隔开)
					developer_ids: '',
					//查询开发商(多个id用英文逗号隔开)
					tag_ids: '',
					//查询标签(多个id用英文逗号隔开)
					sale_state: '',
					//售卖情况:1=在售,2=售罄,3=待售
					sort: 1 //排序:1=默认排序，2=看房次数从大到小（人气排行榜），3=单价从小到大，4=单价从大到小，5=成交量从大到小(热销排行榜)
				},

				choose_sale_state: '',

				//当前选中的售卖情况
				is_single: true,

				min_average_price: '',
				max_average_price: '',
				min_total_price: '',
				max_total_price: '',
				search_type: 1,

				//区域弹窗点开，选择类型:1=区域，2=地铁，3=附近
				now_area_index: 0,

				nowStreetData: [],
				now_subway_index: 0,
				nowPlatformData: [],
				moredev: 3,

				is_ajax_list: false,
				regionStatus: false,
				priceStatus: false,
				houseStatus: false,
				moreStatus: false,
				squareStatus: false,
				

			}
		},
		onLoad: function(options) {
			app.globalData.pagesParam = options;
			
			if(options){
				app.globalData.is_need_page_change = true
			}
			if (!app.globalData.is_need_page_change) {
				this.initData();
			}
		},
		onShow: function() {
			var is_need_change_list = false;
		
			console.log(this.squareArr)
			
			if (app.globalData.is_need_page_change) {
				var param = app.globalData.pagesParam;
				
				app.globalData.is_need_page_change = false;

				if (param.keyword || this.searchCheckJson.keyword) {
					this.searchCheckJson.keyword = param.keyword
					is_need_change_list = true;
				}

				if (param.sale_state) {
					this.searchCheckJson.sale_state = param.sale_state
					this.choose_sale_state = param.sale_state
					is_need_change_list = true;
				}

				if (param.type_id) {
					var typeData = this.searchData.typeData;

					for (let index = 0; index < typeData.length; index++) {
						if (typeData[index].id == param.type_id) {
							typeData[index].is_choose = true;
						} else {
							typeData[index].is_choose = false;
						}
					}
					this.searchData.typeData = param.typeData
					this.searchCheckJson.type_ids = param.type_id
					is_need_change_list = true;
				}

				if (param.tag_id) {
					var tagData = this.searchData.tagData;

					for (let index = 0; index < tagData.length; index++) {
						if (tagData[index].id == param.tag_id) {
							tagData[index].is_choose = true;
						} else {
							tagData[index].is_choose = false;
						}
					}
					this.searchData.tagData = param.tagData
					this.searchCheckJson.tag_ids = param.tag_id
					is_need_change_list = true;
				}

				if (is_need_change_list) {
					this.is_ajax_list = false;
					this.houseList.current_page = 0;
				}
				
				this.initData();
			}

			var now_city = uni.getStorageSync('now_city') || '锡林郭勒盟';

			if (now_city != this.now_city) {
				this.is_ajax_list = false;
				this.searchCheckJson.region = '';
				this.searchCheckJson.street = '';
				this.searchCheckJson.subway_platform_id = 0;
				this.now_area_index = 0;
				this.now_subway_index = 0;
				this.initData();
			}
		},
		onPullDownRefresh: function() {
			uni.showNavigationBarLoading();
			var that = this;
			//模拟加载
			setTimeout(function() {
				that.initData();
				uni.stopPullDownRefresh(); //停止下拉刷新
			}, 1500);
		},
		onReachBottom: function() {
			if (this.houseList.current_page >= this.houseList.last_page) {
				this.loadStatus = 'nomore';
				return false;
			} else {
				this.getHouseList();
			}
		},
		methods: {
			// 跳转页面
			jumpToPages(event) {
				var that = this;
				var jump_type = Number(event.currentTarget.dataset.jump_type);
				var url = event.currentTarget.dataset.url;

				if (jump_type == 1) {
					uni.navigateTo({
						url: url
					});
				} else if (jump_type == 2) {
					app.globalData.nowThat = this;
					functions.checkLogin(function(ret) {
						if (ret) {
							uni.navigateTo({
								url: url
							});
						} else {
							functions.toast('请先登录');
						}
					});
				} else if (jump_type == 3) {
					var tel = app.globalData.config.platform_contact_tel;
					functions.phoneCall({
						phoneNumber: tel //仅为示例，并非真实的电话号码
					});
				}
			},
			
			// 跳转页面 type=1(跳转有tabBar底部的页面)，type=2(正常跳转)
			jumpPages(event) {
				var type = Number(event.currentTarget.dataset.type);
				var url = event.currentTarget.dataset.url;

				if (type == 1) {
					functions.jumpPages(url);
				} else {
					uni.navigateTo({
						url: url
					});
				}
			},
			
			goToDe(event){
				console.log(event);
				console.log('详情id:'+event.id);
				console.log('新房:'+event.house_type_id);
				
				if (event.house_type_id==16) {
					//新房 = 16
					uni.navigateTo({
						url: '/pages/house/building_detail_news/building_detail_news?id='+event.id
					});
				} else if(event.house_type_id==1) {
					// 二手房 = 1
					uni.navigateTo({
						url: '/pages/house/building_detail/building_detail?id='+event.id
					});
				}else{
					// 其他
					uni.navigateTo({
						url: '/pages/house/building_detail/building_detail?id='+event.id
					});
				}
				
			},

			delKeywords() {
				this.searchCheckJson.keyword = '';
				this.houseList.current_page = 0;
				this.getHouseList();
			},
			//关闭弹窗
			closePopup() {
				this.regionStatus = false
				this.priceStatus = false
				this.houseStatus = false
				this.moreStatus = false
				this.squareStatus = false
				this.moredev = 3
			},
			showAllDev() {
				this.moredev = 9999
			},
			// 拨打电话
			bindPhoneCall(e) {
				var tel = app.globalData.config.platform_contact_tel;
				functions.phoneCall({
					phoneNumber: tel //仅为示例，并非真实的电话号码
				});
			},
			jumpToChat(e) {
				var uid = e.currentTarget.dataset.uid || 0;
				var that = this;
				functions.checkLogin(function(ret) {
					if (ret) {
						functions.jumpToChat(uid);
					} else {
						functions.toast('请先登录');
					}
				});
			},
			// 添加预约记录
			addAppointLog(e) {
				this.appoint_type = e.currentTarget.dataset.type;
				this.appoint_subscribe_type = e.currentTarget.dataset.subtype;
				this.broker_user_id = e.currentTarget.dataset.uid || 0;
				// 处理手机号码
				this.appoint_mobile = uni.getStorageSync('mobile') || this.appoint_mobile;
				this.popupStatus = true;
			},
			appoint_mobileFun(e) {
				this.appoint_mobile = e.detail.value
			},
			// 提交预约日志
			submitAppointLog() {
				var that = this;
				if (that.appoint_mobile.length != 11) {
					functions.toast('请输入正确的手机号');
					return false;
				}
				functions.checkLogin(function(ret) {
					if (ret) {
						var appoint_mobile = uni.getStorageSync('mobile');
						that.appoint_mobile = appoint_mobile;

						functions.submitAjaxData(
							that,
							'/api/xiluhouse/house/create_appoint_log', {
								type: that.appoint_type,
								subscribe_type: that.appoint_subscribe_type,
								mobile: that.appoint_mobile,
								broker_user_id: that.broker_user_id,
								city: that.now_city,
							},
							function(res) {
								that.appoint_mobile = that.appoint_mobile;
								that.appoint_mobile_text = appoint_mobile.substr(0, 3) + '****' +
									appoint_mobile.substr(7);
								that.reserveStatus = true;
								that.popupStatus = false;
							}
						);
					} else {
						functions.toast('请先登录');
					}
				});
			},
			closePopupStatus() {
				this.popupStatus = false;
			},
			closeReserveStatus() {
				this.reserveStatus = false;
			},
			//省市区弹窗
			// openarea() {
			// 	this.regionStatus = !this.regionStatus;
			// 	this.priceStatus = false;
			// 	this.houseStatus = false;
			// 	this.moreStatus = false;
				// this.squareStatus = false
			// 	this.moredev = 3;
			// },
			// 面积
			opensquare() {
				this.regionStatus = false;
				this.priceStatus = false;
				this.houseStatus = false;
				this.moreStatus = false;
				this.squareStatus = !this.squareStatus;
				this.moredev = 3;
			},
			//价格弹窗
			openprice() {
				this.regionStatus = false;
				this.priceStatus = !this.priceStatus;
				this.houseStatus = false;
				this.moreStatus = false;
				this.squareStatus = false
				this.moredev = 3;
			},
			//户型弹窗
			openhouse() {
				this.regionStatus = false;
				this.priceStatus = false;
				this.houseStatus = !this.houseStatus;
				this.moreStatus = false;
				this.squareStatus = false
				this.moredev = 3;
			},
			//更多弹窗
			openmore() {
				this.regionStatus = false;
				this.priceStatus = false;
				this.houseStatus = false;
				this.moreStatus = !this.moreStatus;
				this.squareStatus = false
				this.moredev = 3;
			},
			// 选择户型
			chooseroomnum(event) {
				var index = event.currentTarget.dataset.index;
				var roomnumData = this.searchData.roomnumData;
				roomnumData[index].is_choose = !roomnumData[index].is_choose;
				this.searchData.roomnumData = roomnumData;
			},
			// 清空户型选择
			clearroomnum() {
				var roomnumData = this.searchData.roomnumData;
				for (let index = 0; index < roomnumData.length; index++) {
					const element = roomnumData[index];
					roomnumData[index].is_choose = false;
				}
				this.searchData.roomnumData = roomnumData;
				this.searchCheckJson.search_roomnum_ids = '';
				this.houseList.current_page = 0;
				this.getHouseList();
				this.openhouse();
			},
			// 确认户型选择
			confirmroomnum() {
				var roomnumData = this.searchData.roomnumData;
				var search_roomnum_ids_arr = [];

				for (let index = 0; index < roomnumData.length; index++) {
					if (roomnumData[index].is_choose) {
						search_roomnum_ids_arr.push(roomnumData[index].id);
					}
				}
				this.houseList.current_page = 0;
				this.searchCheckJson.search_roomnum_ids = search_roomnum_ids_arr ? search_roomnum_ids_arr.join(',') : '';
				this.getHouseList();
				this.openhouse();
			},
			// 选择类型
			choosetype(event) {
				var index = event.currentTarget.dataset.index;
				var typeData = this.searchData.typeData;
				typeData[index].is_choose = !typeData[index].is_choose;
				this.searchData.typeData = typeData;
			},
			chooseSquare(event) {
				var id = event.currentTarget.dataset.id;
				this.sid = this.sid === id ? null : id; 
				
			},
			// 选择售卖情况
			choosesalestate(event) {
				this.choose_sale_state = event.currentTarget.dataset.type;
			},
			// 选择开发商
			choosedeveloper(event) {
				var index = event.currentTarget.dataset.index;
				var developerData = this.searchData.developerData;
				developerData[index].is_choose = !developerData[index].is_choose;
				this.searchData.developerData = developerData;
			},
			// 清空更多选择
			clearmore() {
				var searchData = this.searchData;
				for (let index = 0; index < searchData.typeData.length; index++) {
					searchData.typeData[index].is_choose = false;
				}
				for (let index = 0; index < searchData.developerData.length; index++) {
					searchData.developerData[index].is_choose = false;
				}
				this.sid = '';
				this.searchData = searchData;
				this.searchCheckJson.type_ids = '';
				this.searchCheckJson.developer_ids = '';
				this.searchCheckJson.sale_state = '';
				this.choose_sale_state = '';
				this.houseList.current_page = 0;

				this.getHouseList();
				this.openmore();
			},
			// 确认更多选择
			confirmmore() {
				var typeData = this.searchData.typeData;
				var type_ids_arr = [];

				for (let index = 0; index < typeData.length; index++) {
					if (typeData[index].is_choose) {
						type_ids_arr.push(typeData[index].id);
					}
				}

				var developerData = this.searchData.developerData;
				var developer_ids_arr = [];

				for (let index = 0; index < developerData.length; index++) {
					if (developerData[index].is_choose) {
						developer_ids_arr.push(developerData[index].id);
					}
				}
				this.searchCheckJson.type_ids = type_ids_arr ? type_ids_arr.join(',') : '';
				this.searchCheckJson.developer_ids = developer_ids_arr ? developer_ids_arr.join(',') : '';
				this.searchCheckJson.sale_state = this.choose_sale_state;
				this.houseList.current_page = 0
				this.getHouseList();
				this.openmore();
			},
			
			// 确认面积
			confirmSquare(){
				let that= this;
				console.log(this.sid)
				this.houseList.current_page = 0;
				this.getHouseList();
				this.opensquare();
			},
			
			//选择单价还是总价
			chooseissingle() {
				this.is_single = !this.is_single;
				this.min_average_price = '';
				this.searchCheckJson.min_average_price = '';
				this.max_average_price = '';
				this.searchCheckJson.max_average_price = '';
				this.min_total_price = '';
				this.searchCheckJson.min_total_price = '';
				this.max_total_price = '';
				this.searchCheckJson.max_total_price = '';
			},
			// 选择单价或总价
			chooseprice(event) {
				var index = event.currentTarget.dataset.index;
				var priceData = this.searchData.priceData;

				if (priceData[index].type == 1) {
					for (let i = 0; i < priceData.length; i++) {
						if (priceData[i].type == 1) {
							priceData[i].is_choose = false;
						}
					}

					this.min_average_price = '';
					this.max_average_price = '';
					this.searchCheckJson.min_average_price = priceData[index].min_price; //最小单价（万元）
					this.searchCheckJson.max_average_price = priceData[index].max_price //最大单价（万元）（-1为无限大）
				} else {
					for (let i = 0; i < priceData.length; i++) {
						if (priceData[i].type == 2) {
							priceData[i].is_choose = false;
						}
					}

					this.min_total_price = '';
					this.max_total_price = '';
					this.searchCheckJson.min_total_price = priceData[index].min_price; //最小总价（万元）
					this.searchCheckJson.max_total_price = priceData[index].max_price //最大总价（万元）（-1为无限大）
				}

				priceData[index].is_choose = !priceData[index].is_choose;
				this.searchData.priceData = priceData;
				this.houseList.current_page = 0

				this.getHouseList();
				this.openprice();
			},
			min_average_price_fuc(e) {
				this.min_average_price = e.detail.value
			},
			max_average_price_fuc(e) {
				this.max_average_price = e.detail.value
			},
			min_total_price_fuc(e) {
				this.min_total_price = e.detail.value
			},

			max_total_price_fuc(e) {
				this.max_total_price = e.detail.value
			},
			// 确认价格搜索
			confirmprice() {
				if (this.is_single && (!this.min_average_price || !this.max_average_price || this.min_average_price > this.max_average_price)) {
					functions.toast('请输入正确的价格');
					return false;
				}

				if (!this.is_single && (!this.min_total_price || !this.max_total_price || this.min_total_price > this.max_total_price)) {
					functions.toast('请输入正确的价格');
					return false;
				}

				var priceData = this.searchData.priceData;

				if (this.is_single) {
					for (let i = 0; i < priceData.length; i++) {
						if (priceData[i].type == 1) {
							priceData[i].is_choose = false;
						}
					}

					this.searchCheckJson.min_average_price = this.min_average_price; //最小单价（元）
					this.searchCheckJson.max_average_price = this.max_average_price //最大单价（元）（-1为无限大）
				} else {
					for (let i = 0; i < priceData.length; i++) {
						if (priceData[i].type == 2) {
							priceData[i].is_choose = false;
						}
					}

					this.searchCheckJson.min_total_price = Number(this.min_total_price)*10000; //最小总价（万元）
					this.searchCheckJson.max_total_price = Number(this.max_total_price)*10000; //最大总价（万元）（-1为无限大）
				}

				this.searchData.priceData = priceData;
				this.houseList.current_page = 0

				this.getHouseList();
				this.openprice();
			},
			// 选择区域搜索类型
			choosesearchtype(event) {
				this.search_type = event.currentTarget.dataset.type;
			},
			// 选择附近
			choosenearby(event) {
				var nearby = event.currentTarget.dataset.nearby;
				this.searchCheckJson.nearby = nearby;
				this.houseList.current_page = 0
				this.getHouseList();
				this.openarea();
			},
			// 选择区域
			chooseregion(event) {
				var index = event.currentTarget.dataset.index;
				var areaData = this.areaData;

				if (index == 0) {
					this.now_area_index = index;
					this.searchCheckJson.region = '';
					this.searchCheckJson.street = '';
					this.houseList.current_page = 0
					this.getHouseList();
					this.openarea();
				} else {
					this.now_area_index = index;
					this.nowStreetData = areaData[index - 1].list
				}
			},
			// 选择街道
			choosestreet(event) {
				var index = event.currentTarget.dataset.index;
				var areaData = this.areaData;
				var nowStreetData = this.nowStreetData;

				if (index == 0) {
					this.searchCheckJson.region = areaData[this.now_area_index - 1].name
					this.searchCheckJson.street = ''
					this.houseList.current_page = 0
				} else {
					this.searchCheckJson.region = areaData[this.now_area_index - 1].name
					this.searchCheckJson.street = nowStreetData[index - 1].name
					this.houseList.current_page = 0
				}
				this.getHouseList();
				this.openarea();
			},
			// 选择地铁线
			choosesubway(event) {
				var index = event.currentTarget.dataset.index;
				var subwayData = this.subwayData;

				if (index == 0) {
					this.now_subway_index = index
					this.searchCheckJson.subway_id = 0
					this.searchCheckJson.subway_platform_id = 0
					this.houseList.current_page = 0
					this.getHouseList();
					this.openarea();
				} else {
					this.now_subway_index = index
					this.nowPlatformData = subwayData[index - 1].list
				}
			},
			// 选择地铁站
			chooseplatform(event) {
				var index = event.currentTarget.dataset.index;
				var subwayData = this.subwayData;
				var nowPlatformData = this.nowPlatformData;

				if (index == 0) {
					this.searchCheckJson.subway_id = subwayData[this.now_subway_index - 1].id
					this.searchCheckJson.subway_platform_id = 0
					this.houseList.current_page = 0
				} else {
					this.searchCheckJson.subway_id = subwayData[this.now_subway_index - 1].id
					this.searchCheckJson.subway_platform_id = nowPlatformData[index - 1].id
					this.houseList.current_page = 0
				}
				this.getHouseList();
				this.openarea();
			},
			doSearch(e) {
				this.searchCheckJson.keyword = e.detail.value
				this.houseList.current_page = 0
				this.getHouseList();
			},
			// 处理已选数据
			handleCheckedDataShow: function(searchData) {

				var tagData = searchData.tagData;
				var tag_ids = this.searchCheckJson.tag_ids;
				var tag_arr = tag_ids ? tag_ids.split(',') : [];

				for (let index = 0; index < tagData.length; index++) {
					const element = tagData[index];
					var id = element.id + '';

					if (tag_arr.indexOf(id) == -1) {
						tagData[index].is_choose = false;
					} else {
						tagData[index].is_choose = true;
					}
				}

				searchData.tagData = tagData; // 处理户型

				var roomnumData = searchData.roomnumData;
				var search_roomnum_ids = this.searchCheckJson.search_roomnum_ids;
				var search_roomnum_arr = search_roomnum_ids ? search_roomnum_ids.split(',') : [];

				for (let index = 0; index < roomnumData.length; index++) {
					const element = roomnumData[index];
					var id = element.id + '';

					if (search_roomnum_arr.indexOf(id) == -1) {
						roomnumData[index].is_choose = false;
					} else {
						roomnumData[index].is_choose = true;
					}
				}
				searchData.roomnumData = roomnumData; // 处理类型

				var typeData = searchData.typeData;
				var type_ids = this.searchCheckJson.type_ids;
				var type_arr = type_ids ? type_ids.split(',') : [];

				for (let index = 0; index < typeData.length; index++) {
					const element = typeData[index];
					var id = element.id + '';

					if (type_arr.indexOf(id) == -1) {
						typeData[index].is_choose = false;
					} else {
						typeData[index].is_choose = true;
					}
				}

				searchData.typeData = typeData; // 处理开发商

				var developerData = searchData.developerData;
				var developer_ids = this.searchCheckJson.developer_ids;
				var developer_arr = developer_ids ? developer_ids.split(',') : [];

				for (let index = 0; index < developerData.length; index++) {
					const element = developerData[index];
					var id = element.id + '';

					if (developer_arr.indexOf(id) == -1) {
						developerData[index].is_choose = false;
					} else {
						developerData[index].is_choose = true;
					}
				}

				searchData.developerData = developerData; // 处理价格

				var priceData = searchData.priceData;

				for (let index = 0; index < priceData.length; index++) {
					priceData[index].is_choose = false;
				}

				searchData.priceData = priceData;
				this.searchData = searchData
			},
			// 获取房源列表信息
			getHouseList: function() {
				var that = this;
				var json = {
					city: that.now_city,
					area:that.sid,//面积
				};
				json.type_ids = this.type_ids?this.type_ids:'';
				json.page = Number(that.houseList.current_page) + 1;
				Object.assign(json, this.searchCheckJson);

				if (json.page > 1 && that.houseList.current_page >= that.houseList.last_page) {
					functions.toast('已加载到底部了');
					this.loadStatus = 'nomore';
					return false;
				}
				this.loadStatus = 'loading';
				functions.getAjaxList(that, '/api/xiluhouse/House/house_list', json, function(res) {
					var houseList = res.data;

					if (json.page > 1) {
						var now_houseList_data = that.houseList.data || [];
						var now_houseList_data = now_houseList_data.concat(houseList.data);
						houseList.data = now_houseList_data;
					}
					if (houseList.current_page >= houseList.last_page) {
						that.loadStatus = 'nomore';
					}

					that.houseList = houseList
				});
			},

			// 获取所有可下拉刷新更新的数据
			initData: function() {
				var that = this;
				this.now_city = uni.getStorageSync('now_city') || '锡林郭勒盟';

				functions.getAjaxData(
					'/api/xiluhouse/universal/region_street_data', {
						city: that.now_city
					},
					function(res) {
						that.areaData = res.data
					}
				); // 获取---通用类-根据城市获取当前地铁数据

				functions.getAjaxData(
					'/api/xiluhouse/universal/subways_data', {
						city: that.now_city
					},
					function(res) {
						that.subwayData = res.data
					}
				); // 获取---通用类-房源类型搜索数据

				functions.getAjaxData(
					'/api/xiluhouse/universal/search_field_data', {
						city: that.now_city
					},
					function(res) {
						// that.searchData= res.data
						that.handleCheckedDataShow(res.data);
					}
				);

				that.houseList.current_page = 0
				that.getHouseList();
			}
		}
	}
</script>

<style scoped lang="scss">
	.pricewrap .rangeprice.leftline {
		width: 285rpx
	}

	.pricewrap .rangeprice.rightline {
		width: 285rpx;
		background-color: #fff
	}

	.icon_reward {
		width: 16rpx;
		height: 16rpx;
		margin-right: 5rpx;
	}

	.number_one {
		height: 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		background: #FE973C;
		border-radius: 5rpx;
		padding: 0 5rpx;
		font-size: 16rpx;
		color: #fff;
		margin-bottom: 12rpx;
		margin-right: 10rpx;
	}

	.icon_map {
		width: 31rpx;
		height: 39rpx;
	}

	.center_slot {
		width: 100vw;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 99999;
		background-color: var(--white);
	}

	.sortbox {
		// position: sticky;
		height: 90rpx;
		line-height: 90rpx;
		border-bottom: 1px solid #f4f3f3;
		// top: calc(var(--status-bar-height) + 88upx);
		background-color: var(--white);
		z-index: 9999999;
	}

	.sortbox .sortitem {
		flex: 1;
		align-items: center;
		justify-content: center;
		display: flex;
	}

	.sortbox .sortitem::after {
		width: 0;
		content: "";
		display: block;
		height: 0;
		margin-left: 14rpx;
		border-top: 8rpx solid #ccc;
		border-right: 7.5rpx solid transparent;
		border-bottom: 0 solid transparent;
		border-left: 7.5rpx solid transparent;
	}

	.sortbox .sortitem.active {
		color: var(--normal);
	}

	.sortbox .sortitem.active::after {
		width: 0;
		content: "";
		display: block;
		height: 0;
		margin-left: 14rpx;
		border-top: 0 solid transparent;
		border-right: 7.5rpx solid transparent;
		border-bottom: 8rpx solid var(--normal);
		border-left: 7.5rpx solid transparent;
	}

	.areas {
		z-index: 2;
		width: 100vw;
		height: 88rpx;
	}

	.city-picker {
		width: 150rpx;
		height: 70rpx;
		border-radius: 50rpx;
		font-size: var(--fs24);
		box-shadow: 0px 4rpx 30rpx 0px rgba(184, 189, 202, 0.3);
	}

	.city-picker::after {
		width: 0;
		content: "";
		display: block;
		margin-top: 4rpx;
		margin-left: 15rpx;
		height: 0;
		border-top: 8rpx solid var(--black);
		border-right: 7.5rpx solid transparent;
		border-bottom: 8rpx solid transparent;
		border-left: 7.5rpx solid transparent;
	}

	.inputbox {
		width: 500rpx;
		height: 70rpx;
		border-radius: 50rpx;
		background-color: rgba(255, 255, 255, 0.3);
		color: var(--black);
		margin-left: 20rpx;
		padding: 0 30rpx;
		box-shadow: 0px 4rpx 30rpx 0px rgba(184, 189, 202, 0.3);
	}

	.icon_search {
		width: 30rpx;
		height: 30rpx;
		margin-right: 20rpx;
	}

	.inputbox input {
		color: var(--black);
		font-size: var(--fs24);
	}

	.houselist {
		padding: 178rpx 40rpx 40rpx;
		/* #ifdef H5 */
		padding-top:45px;
		/* #endif */
	}

	.houselist .houseitem {
		position: relative;
		padding-top: 30rpx;

		.targets {
			position: absolute;
			top: 15rpx;
			left: 15rpx;
			z-index:9;
		}

		.targets view {
			padding: 2rpx 4rpx;
			color: var(--white);
			font-size: var(--fs16);
			margin-right: 10rpx;
			border-radius: 2rpx;
		}

		.targets .tar1 {
			background-color: #FF7B40;
		}

		.targets .tar2 {
			background-color: #FE6075;
		}

		.targets .tar3 {
			background-color: var(--blue);
		}
	}

	.houselist .houseitem .houseimg {
		width: 240rpx;
		height: 190rpx;
		border-radius: 10rpx;
		margin-right: 20rpx;
	}

	.houselist .housename {
		font-size: var(--fs30);
		padding-bottom: 10rpx;
	}

	.houselist .area-size {
		font-size: var(--fs24);
		color: #898989;
	}

	.houselist .targetbox {
		padding: 14rpx 0 0;
		white-space: nowrap;
		overflow-x: scroll;
		width: 100%;
	}

	.houselist .targetitem {
		padding: 2rpx 4rpx;
		background: #cce9ff;
		font-size: var(--fs18);
		color: var(--normal);
		border-radius: 2rpx;
		margin-right: 10rpx;
		margin-bottom: 12rpx;
	}

	.houselist .housecost {
		color: var(--red);
		font-size: var(--fs24);
	}

	.houselist .housecost text {
		font-size: var(--fs34);
	}
	.houselist .housecost .junjia{
		font-size: var(--fs24);
		color: #999;
	}

	.houselist .event {
		padding-top: 11rpx;
		font-size: var(--fs18);
		color: #898989;
	}

	.houselist .event .bao {
		width: 26rpx;
		text-align: center;
		line-height: 26rpx;
		font-size: var(--fs18);
		height: 26rpx;
		border-radius: 5rpx;
		background: linear-gradient(180deg, #00C4FF, var(--normal));
		color: var(--white);
		margin-right: 10rpx;
	}

	.houselist .event .dong {
		width: 26rpx;
		text-align: center;
		line-height: 26rpx;
		font-size: var(--fs18);
		height: 26rpx;
		border-radius: 5rpx;
		background: linear-gradient(270deg, #FF6635, #FFB45C);
		color: var(--white);
		margin-right: 10rpx;
	}

	.houselist .event .hot {
		width: 26rpx;
		text-align: center;
		line-height: 26rpx;
		font-size: var(--fs18);
		height: 26rpx;
		border-radius: 5rpx;
		background: linear-gradient(270deg, #ff5232 0%, #ff6635 100%);
		color: var(--white);
		margin-right: 10rpx;
	}

	.icon_direct {
		width: 32rpx;
		height: 32rpx;
	}
</style>
